<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改信息</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-offset-3 col-md-6">
            <div class="page-header">
                <h2>
                    <small>
                        修改信息
                    </small>
                </h2>
            </div>
        </div>
    </div>

    <div class="row clearfix">
        <div class="col-md-offset-3 col-md-6">
            <form action="${pageContext.request.contextPath}/user/userDo/modify?Jump=${Jump}" method="post">
                <input type="hidden" name="id" value="${user.id}">
                <div class="form-group">
                    <label for="userCode">用户编码：</label>
                    <input type="text" name="userCode" id="userCode" value="${user.userCode}" class="form-control" required>
                    <!-- 放置提示信息 -->
                    <span id="tipsUserCode" style="color:red"></span>
                </div>
                <div class="form-group">
                    <label for="userName">用户名称：</label>
                    <input type="text" name="userName" id="userName" value="${user.userName}" class="form-control" required>
                </div>
                <div class="form-group">
                    <label for="userPassword">用户密码：</label>
                    <input type="text" name="userPassword" id="userPassword" value="${user.userPassword}" class="form-control" required>
                </div>
                <div class="form-group">
                    <label >用户性别：</label>
                    <select name="gender" id="gender" class="form-control">
                        <c:choose>
                            <c:when test="${user.gender == 1 }">
                                <option value="1" selected="selected">男</option>
                                <option value="2">女</option>
                            </c:when>
                            <c:otherwise>
                                <option value="1">男</option>
                                <option value="2" selected="selected">女</option>
                            </c:otherwise>
                        </c:choose>
                    </select>
                </div>
                <div class="form-group">
                    <label for="birthday">出生日期：</label>
                    <input type="text" id="birthday" name="birthday" value="${birthday}" class="form-control" required
                           data-toggle="tooltip" data-placement="right" title="固定格式 0000/00/00">
                </div>

                <div class="form-group">
                    <label for="phone">用户电话：</label>
                    <input type="text" name="phone" id="phone"  value="${user.phone}" class="form-control" required>
                </div>
                <div class="form-group">
                    <label for="address">用户地址：</label>
                    <input name="address" id="address"  value="${user.address}" class="form-control">
                </div>
                <div class="form-group">
                    <label >用户角色：</label>
                    <!-- 列出所有的角色分类 -->
                    <c:choose>
                        <%--个人信息修改职位时0与3不可修改，1与2可修改--%>
                        <%--用户管理信息修改职位时1与2可修改--%>
                        <c:when test="${user.userRole == 0 and Jump.equals('main')}">
                            <select name="userRole" id="userRole" class="form-control" disabled>
                                <option value="0" selected>无</option>
                            </select>
                        </c:when>
                        <c:when test="${user.userRole == 3 and Jump.equals('main')}">
                            <select name="userRole" id="userRole" class="form-control" disabled>
                                <option value="0" selected>普通员工</option>
                            </select>
                        </c:when>
                        <c:when test="${user.userRole == 0 }">
                            <select name="userRole" id="userRole" class="form-control">
                                <option value="0" selected>无</option>
                                <option value="1">系统管理员</option>
                                <option value="2">经理</option>
                                <option value="3">普通员工</option>
                            </select>
                        </c:when>
                        <c:when test="${user.userRole == 1 }">
                            <select name="userRole" id="userRole" class="form-control">
                                <option value="1" selected>系统管理员</option>
                                <option value="2">经理</option>
                                <option value="3">普通员工</option>
                            </select>
                        </c:when>
                        <c:when test="${user.userRole == 2 }">
                            <select name="userRole" id="userRole" class="form-control">
                                <option value="1">系统管理员</option>
                                <option value="2" selected>经理</option>
                                <option value="3">普通员工</option>
                            </select>
                        </c:when>
                        <c:when test="${user.userRole == 3 }">
                            <select name="userRole" id="userRole" class="form-control">
                                <option value="1">系统管理员</option>
                                <option value="2">经理</option>
                                <option value="3" selected>普通员工</option>
                            </select>
                        </c:when>
                    </c:choose>
                </div>
                <div class="form-inline">
                    <div  class="col-md-offset-4">
                        <input type="submit" class="btn btn-default" value="&emsp;修改&emsp;">
                        <button type="button" class="btn btn-default">
                            <c:if test="${Jump.equals('main')}">
                                <a href="${pageContext.request.contextPath}/user/main" >
                                    &emsp;返回&emsp;
                                </a>
                            </c:if>
                            <c:if test="${Jump==null}">
                                <a href="${pageContext.request.contextPath}/user/userDo/queryPage" >
                                    &emsp;返回&emsp;
                                </a>
                            </c:if>
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script src="${pageContext.request.contextPath}/webjars/jquery/3.6.0/jquery.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
        integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<script>
    $(function () {
        //日期栏提示框开启
        $('[data-toggle="tooltip"]').tooltip();
        //用户编码栏失焦
        $('#userCode').blur(function () {
            let userCode = $('#userCode').val();
            console.log(userCode);
            userCodeModifyCheck(userCode);
        });
    })

    //用户编码更新查重
    function userCodeModifyCheck(userCode) {
        $.ajax({
            url:"${pageContext.request.contextPath}/user/register/checkUserCode",
            type:"POST",
            data:{
                //用户编码框中的内容
                registerUserCode:userCode,
                //用户的添加与修改中都要用编码查重，操作不同用于区分
                //添加:整个数据库查重
                //修改:剔除自己进行查重
                OperationName:'modify',
                id:"${user.id}"
            },
            success:function (data) {
                console.log(data);
                if(!data){
                    $('#tipsUserCode').text("*用户编码重复")
                }else{
                    $('#tipsUserCode').text("")
                }
            }
        })
    }
</script>

</body>
</html>
